package com.metagurukul.metagranth.service;

import com.metagurukul.metagranth.model.dao.AnswerDAO;
import com.metagurukul.metagranth.model.dao.QuestionDAO;

/**
 * This class will handle admin related DAOs
 * @author Team MetaGranth
 */

public class AdminQuestionService {	

	/**
	 * This method  will close the approved question
	 * @param int answerId
	 * @return boolean status
	 * @throws Exception
	 */
	
	public static boolean closeQuestionApproveAnswer(int answerId) throws Exception {
		
		boolean status = false;
		try {
			// updating answer status as approved
			int statusUpdateAnswer = AnswerDAO.updateAnswerStatus(answerId);
			
			// updating question status as closed
			int statusUpdateQuestion = QuestionDAO.updateQuestionStatus(answerId);

			// if both updation is successful then status is set as true otherwise false
			if (statusUpdateAnswer == 1 && statusUpdateQuestion == 1) {
				status = true;
			} else{
				status = false;
			}
			return status;
		}catch(Exception exception){
			throw exception;
		}
	}

	/**
	 * This method will count the closed questions
	 * @return no of closed questions
	 * @throws Exception
	 */
	
	public static int countCloseQuestion() throws Exception {
		try{
			// calling QuestionDAO to count closed questions
			int count = QuestionDAO.countClosedQuestion();
			return count;
		} catch(Exception exception) {
			throw exception;
		}
	}

}
